
package biblioteca.dao;

import java.io.Serializable;
import java.util.List;
import javax.persistence.EntityManager;




public class DaoImplementation <T , PK extends Serializable> implements GenericDao<T, PK> {

	EntityManager em;
	
	
	@Override
	public void update(T object) {
		em.merge(object);		
	}

	@Override
	public void remove(T object) {
		em.remove(em.merge(object));
	}

	@Override
	public void remove(Class<T> typeClass, PK clave) {
		T object = em.find(typeClass, clave);
        em.remove(em.merge(object));	
	}

	@Override
	public void insert(T object) {
		em.persist(object);		
	}

	@Override
	public void cerrar() {
		em.close();		
	}

	@Override
	public List<T> getPaginated(Class<T> typeClass, int startPosition,
			int maxResult) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<T> getOrderedPaginated(Class<T> typeClass, int startPosition,
			int maxResult, String order, int dir) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<T> getAll(Class<T> typeClass) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Integer countAll(Class<T> typeClass) {
		em = EMF.get().createEntityManager();
		final StringBuilder sql =new StringBuilder("select count()c from").append(typeClass.getSimpleName()).append("c");
		return (Integer) em.createQuery(sql.toString()).getSingleResult();
	}

	@Override
	public T findByPK(Class<T> typeClass, PK id) {
		// TODO Auto-generated method stub
		return null;
	}
	
	
	
	
}
